<?php
/**
 * 功能：引导公共部份(Factory)
 * 说明：bootstrap.php
 * 创建日期：2012-04-01
 * 更新日期：
 * 作者：Mirze
 * 补充说明： 
 * 
 */
//error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');

include_once('core/throw_exception.php'); //异常处理类
include_once('core/common/function.php');

/** Smarty **/
function Smarty($config = array())
{
	//smarty 缺省配置
	$define_config = array(
		'templates' => TPL_DIR,
		'templates_c' => TMP_DIR . "/templates_c",
		'configs' => TMP_DIR . "/configs",
		'cache' => TMP_DIR . "/cache",
	);
	$smarty_config = array_merge($define_config, $config);

	if (!file_exists($smarty_config['templates_c'])){			
		@mkdir($smarty_config['templates_c'], 0777);
		//@chmod($smarty_config['templates_c'], 0777);
	}

	include_once(VENDOR_DIR . '/Smarty/Smarty.class.php');
	$smarty = new Smarty();
	$smarty->setTemplateDir($smarty_config['templates']);
	$smarty->setCompileDir($smarty_config['templates_c']);
	$smarty->setConfigDir($smarty_config['configs']);
	$smarty->setCacheDir($smarty_config['cache']);

	return $smarty;	
}

/**
  +----------------------------------------------------------
 * M函数用于实例化一个没有模型文件的Model
  +----------------------------------------------------------
 * @param string name Model名称 支持指定基础模型 例如 MongoModel:User
 * @param string tablePrefix 表前缀
 * @param mixed $connection 数据库连接信息
  +----------------------------------------------------------
 * @return Model
  +----------------------------------------------------------
 */
function M($name='', $tablePrefix='',$connection='') 
{
	$model_name = trim($name);
	if('' == $model_name) {
		$file = LIB_DIR . '/core/Model.php';
		$class = 'Model';
	} else {
		$file = MODEL_DIR . '/' . $class . '.php';	
		$class = ucfirst($model_name);
	}
	if(!file_exists($file)) exit($file."不存在");
	require_once($file);
	return new $class($model_name,$tablePrefix,$connection);
}






?>